﻿namespace MyTRCP.Common.Models
{
    public class ChannelPayload
    {
        public byte Id { get; set; }
        public ChannelInfo ChannelInfo { get; set; }
        public ChannelPayload(byte id, ChannelInfo channelInfo)
        {
            Id = id;
            ChannelInfo = channelInfo;
        }

        public ChannelPayload(byte[] data)
        {
            if (data.Length < 25)
                throw new ArgumentException("字节数组长度过小（25）", nameof(data));
            Id = data[0];
            byte[] chData = new byte[data.Length - 1];
            Array.Copy(data, 1, chData, 0, chData.Length);
            ChannelInfo = new ChannelInfo(chData);
        }
        public byte[] WriteToBytes()
        {
            byte[] bytes = new byte[25];
            bytes[0] = Id;
            byte[] ciBytes = ChannelInfo.WriteToBytes();
            Array.Copy(ciBytes, 0, bytes, 1, ciBytes.Length);
            return bytes;
        }
    }
}